﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using Lswweb.Model;
using Lswweb.Domain;

namespace Lswweb.Controls
{
    public class UserAdminPowers : SkinnedWebControl
    {
        //private MapTreeView powersTreeView;
        private CheckBoxGridView checkBoxGridView;
        private Button btnConfirm;

        protected override void InitializeSkin(System.Web.UI.Control skin)
        {
            //powersTreeView = (MapTreeView)skin.FindControl("powersTreeView");
            checkBoxGridView = (CheckBoxGridView)skin.FindControl("checkBoxGridView");
            btnConfirm = (Button)skin.FindControl("btnConfirm");

            btnConfirm.Click += new EventHandler(btnConfirm_Click);
            checkBoxGridView.GridViewDataSourceHandler += new DataSourceHandler(checkBoxGridView_GridViewDataSourceHandler);

            checkBoxGridView.ValueField = "Name";
            checkBoxGridView.TextField = "Text";
            checkBoxGridView.PathField = "Path";
            checkBoxGridView.SelectValues = Users.GetAaminPowers(UserId);
        }

        IList checkBoxGridView_GridViewDataSourceHandler(string args)
        {
            return (IList)Maps.Content.GetChildNodes(MapType.AdminMenu, args);
        }

        void btnConfirm_Click(object sender, EventArgs e)
        {
            string value = checkBoxGridView.SelectValues;
       
            Users.SetAdminPowers(UserId, value);
        }

        private int UserId
        {
            get { return SiteContext.Current.Id; }
        }

        protected override string DefaultSkinFilename
        {
            get { return "UserAdminPowers.ascx"; }
        }
    }
}
